package com.projectName.www.dao;

import com.projectName.www.util.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public abstract  class BaseDao {

    public static int executeUpdata(String sql,Object...params) throws Exception
    //sql:带占位符的语句；params：占位符的值；返回影响的行数
    {
        Connection con = JdbcUtils.getConnection();
        PreparedStatement p1 = con.prepareStatement(sql);

        for (int i = 1; i <=params.length; i++) {
            p1.setObject(i,params[i-1]);
        }
         int i =p1.executeUpdate();

        return i;
        };
    public static ResultSet executeQuery(String sql,Object...params) throws Exception {

        Connection con = JdbcUtils.getConnection();
        PreparedStatement s = con.prepareStatement(sql);
        for (int i = 1; i <=params.length; i++) {
            s.setObject(i,params[i-1]);
        }
        ResultSet r = s.executeQuery();
        return  r;

    }


}
